using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using Banshee.Base;
using Banshee.Sources;
using System.ComponentModel;
using System.Windows.Forms;

namespace Banshee
{
    public class TrackSource
    {
        public event EventHandler Updated;
        public event EventHandler Stopped;
        public event EventHandler Cleared;

        public TrackSource()
        {

        }
        private void RaiseCleared(object sender, EventArgs e)
        {
            EventHandler handler = Cleared;
            if (handler != null)
                handler(sender, e);
        }
        private void RaiseUpdated(object o, EventArgs args)
        {
            EventHandler handler = Updated;
            if (handler != null)
                handler(o, args);
        }
        protected Controls.SearchableSortableBindingList<TrackInfo> _tracks = new Controls.SearchableSortableBindingList<TrackInfo>();

        public Controls.SearchableSortableBindingList<TrackInfo> Tracks
        {
            get { return _tracks; }
            set { _tracks = value; }
        }
        TimeSpan totalDuration = new TimeSpan(0);

        public TimeSpan TotalDuration
        {
            get { return totalDuration; }
            set { totalDuration = value; }
        }
        public void Clear()
        {
            _tracks.Clear();
            RaiseCleared(this, new EventArgs());
        }
        void AddTrack(TrackInfo track)
        {
            _tracks.Add(track);
        }
        public void SetCustomSource(Source source)
        {
            Clear();

            totalDuration = TimeSpan.FromSeconds(0);
            foreach (TrackInfo track in source.Tracks)
            {
                _tracks.Add(track);
                TimeSpan dur = track.Duration;
                totalDuration.Add(dur);
            }
            RaiseUpdated(this, new EventArgs());
        }
        public void Reload()
        {
            Clear();

            totalDuration = TimeSpan.FromSeconds(0);
            foreach (TrackInfo track in SourceManager.ActiveSource.Tracks)
            {

                _tracks.Add(track);
                TimeSpan dur = track.Duration;
                totalDuration.Add(dur);
            }
            RaiseUpdated(this, new EventArgs());

        }
    }
}
